<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="admin/fragment :: head('博客列表')">
</head>
<body>
<!--导航 ui表示ui inverted与当前色相反  attached表依附，去圆角  segment表片段-->
<div th:replace="admin/fragment :: menu(1)"></div>
<!--菜单中选中的样式  pointing-->
<div class="ui menu attached pointing right aligned">
    <div class="ui container">
        <div class="right menu">
            <a href="#" class="item">发布</a>
            <a href="#" class="ui item active teal">列表</a>
        </div>
    </div>
</div>
<!--中间内容-->
<div class="m-padded-tb-large m-container">
    <div class="ui container">
        <div  class="ui form segment">
            <input type="hidden" name="page">
            <div class="inline fields">
                <div class="field">
                    <input type="text" name="title" placeholder="标题">
                </div>
                <div class="field">
                    <div class="ui selection dropdown">
                        <input type="hidden" name="typeId">
                        <i class="ui dropdown icon"></i>
                        <!--default表示默认，展示为灰色字体   text表示，点击了某个东西，该地方就变成那个文本-->
                        <div class="default text">
                            分类
                        </div>
                        <div class="menu">
                            <div class="item"></div>
                            <div th:each="type:${types}" class="item" th:data-value="${type.id}" th:text="${type.name}">学习</div>
                            <!--/*-->
                            <div class="item" data-value="2">游戏</div>
                            <div class="item" data-value="3">生活</div>
                            <!--*/-->
                        </div>
                    </div>
                </div>
                <div class="field">
                    <div class="ui checkbox">
                        <input type="checkbox" id="recommend" name="recommend">
                        <label for="recommend">推荐</label>
                    </div>
                </div>
                <div class="field">
                    <button type="button" id="search-btn" class="ui teal basic button mini"><i class="search icon"></i>搜索</button>
                </div>
            </div>
        </div>
        <!--celled  网格线-->
        <div id="table-container">
            <table th:fragment="blogList" class="ui compact table">
                <thead>
                <tr>
                    <th>序号</th>
                    <th>标题</th>
                    <th>类型</th>
                    <th>推荐</th>
                    <th>状态</th>
                    <th>创建时间</th>
                    <th>更新时间</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <tr th:each="blog,iterStat: ${page.content}">
                    <td  th:text="${iterStat.count + (page.getNumber())*page.getSize()}">1</td>
                    <td th:text="${blog.title}">刻意练习清单</td>
                    <td th:text="${blog.type.name}">认知升级</td>
                    <td th:text="${blog.recommend}? '是': '否'">是</td>
                    <td th:text="${blog.published}? '已发布': '草稿'">是</td>
                    <td th:text="${blog.createTime}">2020-12-12 09:20</td>
                    <td th:text="${blog.updateTime}">2020-12-12 09:20</td>

                    <td >
                        <a href="#" th:href="@{/admin/blogs/{id}/input(id=${blog.id})}" class="ui button basic teal m-padded-small">编辑</a>
                        <a href="#" th:data-b_id="${blog.id}" th:data-b_title="${blog.title}"  th:onclick="setDelParam(this.getAttribute('data-b_id'),this.getAttribute('data-b_title'))" class="ui button basic red m-padded-small">删除</a>
                    </td>
                </tr>
                </tbody>
                <tfoot>
                <tr>
                    <!--colspan 合并单元格-->
                    <th colspan="8">
                        <a th:href="@{/admin/blogs/input}" class="ui button left floated teal teal mini">新增</a>
                        <div class="ui right floated pagination menu mini" th:if="${page.getTotalPages() > 1}">
                            <a class="icon item" onclick="page(this)" th:attr="data-page=${page.getNumber() - 1}" th:unless="${page.isFirst()}">
                                <i class="left chevron icon" ></i>
                            </a>
                            <div th:each="idx:${#numbers.sequence(0,page.getTotalPages()-1)}">
                                <a onclick="page(this)" class="item" th:text="${idx}+1" th:attr="data-page=${idx}"   th:classappend="${idx == page.getNumber()} ? 'active'">1</a>
                            </div>


                            <a class="icon item" th:attr="data-page=${page.getNumber() + 1}"  th:unless="${page.isLast()}">
                                <i class="right chevron icon"></i>
                            </a>
                        </div>
                    </th>
                </tr>

                </tfoot>
            </table>

            <div class="ui success message" th:unless="${#strings.isEmpty(message)}">
                <i class="icon close"></i>
                <div class="header">提示：</div>
                <p th:text="${message}">恭喜，操作成功</p>
            </div>

        </div>

    </div>
</div>
<div class="ui small modal">
    <i class="close icon"></i>
    <div class="header">
        删除分类
    </div>
    <div class="content">
        <p>确定删除该博客吗？</p>
    </div>

    <div class="actions">
        <div class="ui button negative ">取消</div>
        <div class="ui button approve positive right">确定</div>
    </div>
</div>
<input type="hidden" id="deleteId">


<!--底部  vertical垂直-->
<!--<div th:replace="admin/fragment :: footer"></div>-->



<script src="https://cdn.jsdelivr.net/npm/jquery/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.js"></script>


<script>
    $('.menu.toggle').click(function () {
        $('.m-item').toggleClass('m-mobile-hide');
    });

    $('.ui.dropdown').dropdown({
        on : 'hover'
    });
    function showDelete() {
        $('.small.modal').modal({
            onApprove : function() {
                // window.location.href="/admin/types/"+Number($("#deleteId").val())+"/delete";
                window.location.href="/admin/blogs/"+$("#deleteId").val()+"/delete";
            }
        })
            .modal('show')
        ;
    }
    function setDelParam(id,name){
        $("#deleteId").val(id);
        $("#deleteName").val(name);
        showDelete();
    }

    function page(obj) {
        $("[name='page']").val($(obj).data("page"));
        loadData();
    }

    $("#search-btn").click(function () {
        loadData();
    });

    function loadData() {
        $("#table-container").load(/*[[@{/admin/blogs/search}]]*/"/admin/blogs/search",{
            title: $("[name='title']").val(),
            typeId: $("[name='typeId']").val(),
            recommend: $("[name='recommend']").prop('checked'),
            page: $("[name='page']").val(),

        });
    }

    $(".message .close").on('click',function () {
        $(this).closest(".message").transition('fade');
    });




</script>


</body>

</html>